<?php
/**
 * Created by 绵阳人维网络科技有限公司.
 * User: 罗东华
 * Date: 2016/3/11
 * Time: 15:38
 */
namespace Admin\Controller;
use Common\Controller\LdhC;
class AdminBase extends LdhC{
    public static $userinfo;
    public static $role_ids;

    public function _initialize(){
        //定义后台
        define('IN_ADMIN',true);
        //东哥权限检查
        $this->jurisdiction();


    }
    /**
     * 分页输出
     * @param type $total 信息总数
     * @param type $size 每页数量
     * @param type $number 当前分页号（页码）
     * @param type $config 配置，会覆盖默认设置
     * @return type
     */
    protected function Pages($table, $where=true,$field='',$order=true,$size = 5, $number = 0, $config = array()) {

        $total=M($table)->where($where)->count();
        $Page =page($total, $size, $number, $config);
        $Page->SetPager('default', '<span class="all">共有{recordcount}条信息</span>{first}{prev}{liststart}{list}{listend}{next}{last}');
        $lists = M($table)->field($field)->where($where)->order($order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
     //  echo  M($table)->_sql();exit;
        $this->assign("Page", $Page->show());
        $this->assign("total", $total);

        return $lists;
    }
    /*权限检查*/
    private function jurisdiction(){
        //检查管理员登陆
        if(!self::$userinfo=D('Admin')->admin_info()){
            $this->redirect('Public/login');
        }

        /*检查菜单是否存在*/
        if(!$act_menu=D('Admin','Logic')->act_menu()){
            $this->error('地址菜单错误！','',50);
        }

        if(self::$userinfo['role_id']!=0){
            /*检查菜单权限*/
            self::$role_ids=$role_ids=M('role')->where(array('id'=>self::$userinfo['role_id']))->cache(true)->getField('menu_ids');
            $roles=explode(',',$role_ids);
            if(!in_array($act_menu['id'],$roles)){
                 $this->error('无操作权限!');
            }
        }

    }


}